import * as Pinia from 'pinia'
import { createSSRApp } from 'vue'
import App from './App.vue'
import tui from './common/httpRequest'
import propsConfig from './components/thorui/tui-config/index.js'
import setupRouteGuard from './utils/routeGuard'

//全局组件配置
uni.$tui = propsConfig

const t = uni.getSystemInfoSync().theme;
const theme = {
  primary: function() {
    return t === 'dark' ? '#f59e0b' : '#fcd34d';
  },
  onPrimary: function() {
    return t === 'dark' ? '#f3f4f6' : '#030712';
  },
  secondary: function() {
    return '#8b5cf6';
  },
  onSecondary: function() {
    return '#FFFFFF';
  },
  surface: function() {
    return t === 'dark' ? '#030712' : '#FFFFFF';
  },
  onSurface: function() {
    return t === 'dark' ? '#f3f4f6' : '#030712';
  },
  error: function() {
    return t === 'dark' ? '#EF4444' : '#EF4444';
  },
  onError: function() {
    return t === 'dark' ? '#FFFFFF' : '#FFFFFF';
  },
}

export function createApp() {
  const app = createSSRApp(App)
  app.use(Pinia.createPinia())
  app.use(setupRouteGuard)
  app.config.globalProperties.tui = tui;
  app.config.globalProperties.$theme = theme;
  return {
    app,
    Pinia,
  }
}
